home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS26.ADF
/
HexDump
/
Hex.mod
< prev
next >
Wrap
Text File
|
1989-01-26
|
5KB
|
169 lines
IMPLEMENTATION MODULE Hex;
FROM InOut IMPORT WriteString, WriteLn, WriteCard;
FROM LongInOut IMPORT WriteLongCard, WriteLongHex;
FROM Strings IMPORT Length;
FROM SYSTEM IMPORT LONGWORD, ADDRESS, TSIZE;
PROCEDURE ConvertHexStringToCardinal (VAR Num : LONGCARD;
NumLocation : str80);
(* This procedure converts the hex input string to cardinal in
order to convert to an address. *)
VAR
Index : INTEGER;
Temp : CARDINAL;
Temp1 : LONGCARD;
Dummy : CHAR;
MaxCount : INTEGER;
BEGIN
Index := 0;
MaxCount := Length(NumLocation);(* This is different than HexDump *)
WHILE Index < MaxCount DO
Dummy := NumLocation[Index];
IF((Dummy >= 'A') AND (Dummy <= 'F')) THEN
Temp := ORD(Dummy) - ORD('A') + 10;
ELSE
Temp := ORD(Dummy) - ORD('0');
END;(* IF *)
Temp1 := LONGCARD(Temp);
Num := 16 * Num + Temp1;
Index := Index + 1;
END; (* WHILE *)
RETURN;
END ConvertHexStringToCardinal;
PROCEDURE HexDump( StartAddress : ADDRESS;
WordCount : LONGCARD;
Out : OutType);
(* This procedure dumps memory in hex. *)
VAR
loc : ADDRESS;
count : LONGCARD;
BEGIN
loc := StartAddress;
FOR count := 1 TO WordCount DO
(* Write the line starting address and keep line to a length
of eight.*)
IF count MOD 8 = 1 THEN
WriteLongHex(LONGCARD(loc),8);
WriteString(': ');
END;(* IF *)
(* Write the hex value of memory. *)
WriteHex(CARDINAL(loc^),LeftByte,RightByte,Out);
INC(loc,TSIZE(CARDINAL));
WriteString(Out);
WriteString(' ');
WriteChar(CharOut,CharIndex,LeftByte,RightByte);
IF (count MOD 8 = 0) THEN
WriteString(CharOut);
WriteLn;
END; (* IF *)
END;(* FOR *)
WriteLn;
RETURN;
END HexDump;
PROCEDURE WriteHex( Input : CARDINAL;
VAR LeftByte : CARDINAL;
VAR RightByte : CARDINAL;
VAR Out : OutType);
TYPE
DivisorType = ARRAY[0..3] OF CARDINAL;
VAR
Index : CARDINAL;
Temp : CARDINAL;
Divisor : DivisorType;
x : CARDINAL;
PROCEDURE HexOut(Temp : CARDINAL;
VAR Out : OutType;
Index : CARDINAL);
BEGIN
CASE Temp OF
0 : Out[Index] := '0' |
1 : Out[Index] := '1' |
2 : Out[Index] := '2' |
3 : Out[Index] := '3' |
4 : Out[Index] := '4' |
5 : Out[Index] := '5' |
6 : Out[Index] := '6' |
7 : Out[Index] := '7' |
8 : Out[Index] := '8' |
9 : Out[Index] := '9' |
10 : Out[Index] := 'A' |
11 : Out[Index] := 'B' |
12 : Out[Index] := 'C' |
13 : Out[Index] := 'D' |
14 : Out[Index] := 'E' |
15 : Out[Index] := 'F';
END; (* CASE *)
RETURN;
END HexOut;
BEGIN
Divisor[0] := 4096;
Divisor[1] := 256;
Divisor[2] := 16;
Divisor[3] := 1;
FOR Index := 0 TO 3 DO
IF Index = 2 THEN
(* Save the right byte. *)
RightByte := Input;
LeftByte := 0;
FOR x := 0 TO 1 DO
(* Get the left byte. *)
IF((Out[x] >= 'A') AND (Out[x] <= 'F')) THEN
LeftByte := 16 * LeftByte + (ORD(Out[x]) -
ORD('A') + 10);
ELSE
LeftByte := 16 * LeftByte + ORD(Out[x]) - ORD('0');
END; (* IF *)
END; (* FOR *)
END; (* IF *)
Temp := Input DIV Divisor[Index];
(* Generate hex output. *)
HexOut(Temp,Out,Index);
Input := Input - Temp * Divisor[Index];
END; (* FOR *)
RETURN;
END WriteHex;
PROCEDURE WriteChar(VAR CharOut : CharType;
VAR CharIndex : CARDINAL;
LeftByte : CARDINAL;
RightByte : CARDINAL);
(* This procedure generates the ASCII equivalent of the hex values. *)
BEGIN
(* For the left byte generate ASCII character else generate a
period. *)
IF((CHR(19H)<CHR(LeftByte))AND(CHR(LeftByte)<CHR(7EH))) THEN
CharOut[CharIndex] := CHR(LeftByte);
ELSE
CharOut[CharIndex] := CHR(2EH);
END; (* IF *)
CharIndex := CharIndex + 1;
(* For the right byte generate ASCII character else generate a
period. *)
IF((CHR(19H)<CHR(RightByte))AND(CHR(RightByte)<CHR(7EH))) THEN
CharOut[CharIndex] := CHR(RightByte);
ELSE
CharOut[CharIndex] := CHR(2EH);
END; (* IF *)
CharIndex := CharIndex + 1;
IF CharIndex = 17 THEN CharIndex := 1 END;
RETURN;
END WriteChar;
END Hex.